home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cl_7_bug.zip / BUG_1.C next >
C/C++ Source or Header  |  1992-10-07  |  2KB  |  94 lines

  1. /*
  2.   Test if cl alias (?) bugg (there isn't any use of alias in this code)
  3.   or double loop variable bugg (two loops, if the first is removed it works)
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. typedef struct fileinfo        /* Struct returned from my_dir & my_stat */
  9. {
  10.   char            *name;
  11. } FILEINFO;
  12.  
  13. typedef struct my_dir        /* Struct returned from my_dir */
  14. {
  15.   struct fileinfo    *dir_entry;
  16.   int number_off_files;
  17. } MY_DIR;
  18.  
  19. void test_file(FILEINFO *test);
  20. int get_filename(MY_DIR *dir_info);
  21.  
  22.     /* This function breaks when compiling with
  23.        cl -Ox -AL.
  24.        Code breaks when using test_file() in loop 
  25.        (possibly alias test in cl) and the result
  26.        is a loop of garbage. (se bugg_1.cod)
  27.     */
  28.  
  29. int main(int argc,char *argv[])
  30. {
  31.   MY_DIR dir_info;
  32.   FILEINFO fileinfo[3];
  33.  
  34.   fileinfo[0].name="ALLOC";
  35.   fileinfo[1].name="ALLOCA";
  36.   dir_info.dir_entry=fileinfo;
  37.   dir_info.number_off_files=2;
  38.   
  39.   printf("get_filename returns: %d, Should return 5\n",
  40.        get_filename(&dir_info));
  41.   return(0);
  42. }
  43.  
  44.     /* Expand inputed filename */
  45.  
  46. int get_filename(MY_DIR *dir_info)
  47. {
  48.   register int i;
  49.   int  k_length;
  50.   unsigned int count;
  51.   char *part_name,*pos,*p_pos;
  52.   struct fileinfo *best_info;
  53.  
  54.   part_name="A";
  55.   count=0; k_length= 1000;
  56.  
  57.   for (i=0 ; i < dir_info->number_off_files ; i++)
  58.     {
  59.     /* If next for-loop and test is removed the code works */
  60.       for (p_pos=part_name, pos=dir_info->dir_entry[i].name; *p_pos ;
  61.        pos++,p_pos++)
  62.     if (*pos != *p_pos)
  63.       break;
  64.       if (!*p_pos)
  65.     {        /* In this example this is allways true */
  66.       if (count++)
  67.         {
  68.           register int j;
  69.           /* This loop will be garbage */
  70.           for (j=0 ; j < k_length ; j++)
  71.         if (best_info->name[j] != dir_info->dir_entry[i].name[j])
  72.           break;
  73.           k_length=j;
  74.           /* end garbage */
  75.         }
  76.       else
  77.         {
  78.           best_info= &(dir_info->dir_entry[i]);
  79.           k_length= strlen(best_info->name);
  80.         }
  81.       /*  If the next row is removed the program works */
  82.       test_file(&dir_info->dir_entry[i]);
  83.     }
  84.     }
  85.  
  86.   return k_length;
  87. }
  88.  
  89. void test_file(FILEINFO *test)
  90. {
  91.   return;
  92. }
  93.  
  94.